package main.java.indi.zyj.coderecord;

import java.util.Arrays;

public class PivotIndex {

    public int pivotIndex(int[] nums) {

        int total = Arrays.stream(nums).sum();
        int sum = 0;

        for (int i = 0; i < nums.length; i++) {
            if (total - nums[i] == 2 * sum) {
                return i;
            }
            sum += nums[i];
        }

        return -1;

    }

}
